/* *****************************************************************************
 * JFab (http://code.google.com/p/jfab)
 * Copyright (c) 2011 JFab.org
 * Admin jfab@jeffreythompson.net
 *
 * See the file "LICENSE.txt" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * *****************************************************************************/

package org.jfab.core.factory;

import java.util.List;

import org.apache.commons.lang3.Validate;
import org.jfab.core.collection.CGAnnotationList;
import org.jfab.core.collection.CGConstructorList;
import org.jfab.core.collection.CGEnumItemList;
import org.jfab.core.collection.CGFieldList;
import org.jfab.core.collection.CGInitializationBlockList;
import org.jfab.core.collection.CGMethodList;
import org.jfab.core.collection.CGTypeList;
import org.jfab.core.collection.CommentList;
import org.jfab.core.collection.ModifierList;
import org.jfab.core.model.CGEnum;

/**
 * Provides an enum factory.
 */
public final class DefaultCGEnumFactory implements CGEnumFactory
{
    @Override
    public final CGEnum createEnum(final CGTypeList referencedTypes,
            final String packageName, final CommentList commentLines,
            final CGAnnotationList annotations, final ModifierList modifiers,
            final String enumName, final List<String> typeParameters,
            final CGEnumItemList enumItems,
            final CGInitializationBlockList initializationBlocks,
            final CGConstructorList constructors, final CGFieldList fields,
            final CGMethodList methods)
    {
        Validate.notEmpty(enumName, "enumName is empty");

        final CGEnum answer = new CGEnum();

        answer.setName(enumName);
        answer.setPackageName(packageName);

        if (annotations != null)
        {
            answer.getAnnotations().addAll(annotations);
        }

        if (modifiers != null)
        {
            answer.getModifiers().addAll(modifiers);
        }

        if (commentLines != null)
        {
            answer.getCommentLines().addAll(commentLines);
        }

        if (constructors != null)
        {
            answer.getConstructors().addAll(constructors);
        }

        if (typeParameters != null)
        {
            answer.getTypeParameters().addAll(typeParameters);
        }

        if (enumItems != null)
        {
            answer.getEnumItems().addAll(enumItems);
        }

        if (initializationBlocks != null)
        {
            answer.getInitializationBlocks().addAll(initializationBlocks);
        }

        if (fields != null)
        {
            answer.getFields().addAll(fields);
        }

        if (methods != null)
        {
            answer.getMethods().addAll(methods);
        }

        if (referencedTypes != null)
        {
            answer.getReferencedTypes().addAll(referencedTypes);
        }

        return answer;
    }
}
